﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web_Oto.Business;

namespace Web_Oto.UC
{
    public partial class Banner : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
                GetBanner();
        }

        private void GetBanner()
        {
            var bannerBus = new BannerBus();
            var banners = bannerBus.GetAllBanners();
            var sb = new StringBuilder();
            var index = 0;
            var path = ConfigurationManager.AppSettings["bannerPath"];
            foreach (var banner in banners)
            {
                sb.Append("<li>");
                if (!string.IsNullOrEmpty(banner.Url))
                    sb.AppendFormat("<a href='{0}'>", banner.Url);
                sb.AppendFormat("<img src='{3}/{0}' alt='{1}' title='{1}' id='wows1_{2}' />", banner.Image, banner.Intro, index, path);
                if (!string.IsNullOrEmpty(banner.Url))
                    sb.Append("</a>");
                sb.Append("</li>");
                index++;
            }
            ltrbanners.Text = sb.ToString();
        }
    }
}